/** 
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.tompai.datagather.twitter;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import com.tompai.datagather.twitter.acount.TweetBean;

/**
 * @desc: datagather-tools
 * @name: TwitterSearchImpl.java
 * @author: tompai
 * @createTime: 2018年5月2日 上午10:43:20
 * @history:
 * @version: v1.0
 */
public class TwitterSearchImpl extends TwitterSearch {

	private final AtomicInteger counter = new AtomicInteger();

	@Override
	public boolean saveTweets(List<Tweet> tweets) {
		if (tweets != null) {
			for (Tweet tweet : tweets) {
				System.out
						.println(counter.getAndIncrement() + 1 + "[" + tweet.getCreatedAt() + "] - " + tweet.getText());
				if (counter.get() >= 10) {
					return false;
				}
			}
		}
		return true;
	}

	public static void main(String[] args) throws InvalidQueryException {
		TwitterSearch twitterSearch = new TwitterSearchImpl();
		twitterSearch.search("apple", 2 * 1000);
	}
}